$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'generator/activityinfo/list',
        datatype: "json",
        colModel: [			
			{ label: '序号', name: 'activityno', index: 'activityNo', width: 50, key: true },
			{ label: '活动主题', name: 'theme', index: 'theme', width: 80 }, 			
			{ label: '活动日期', name: 'activitydate', index: 'activitydate', width: 80 }, 			
			{ label: '活动安排内容', name: 'activitydesc', index: 'activitydesc', width: 80 }, 			
			{ label: '计划成本', name: 'fee', index: 'fee', width: 80 }, 			
			{ label: '人数', name: 'peoples', index: 'peoples', width: 80 }, 			
			{ label: '活动负责人', name: 'activitior', index: 'activitior', width: 80 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/employee/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.employee.name;
						}
					}
				});
				return result;
			}}, 			
			{ label: '审批内容', name: 'confirmremark', index: 'confirmRemark', width: 80 }, 			
			{ label: '活动负责部门', name: 'deptno', index: 'deptNo', width: 80 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/department/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.department.name;
						}
					}
				});
				return result;
			}}, 			
			{ label: '活动审批人', name: 'confirmer', index: 'confirmer', width: 80 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/employee/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.employee.name;
						}
					}
				});
				return result;
			}}, 			
			{ label: '审批结论', name: 'confirmdesc', index: 'confirmdesc', width: 80 }		
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    
    $("#giveperNojqGrid").jqGrid({
        url: baseURL + 'generator/employee/list',
        datatype: "json",
        colModel: [			
			{ label: '员工序号', name: 'employeeno', index: 'employeeNo', width: 100, key: true },
			{ label: '员工角色', name: 'employeetype', index: 'employeeType', width: 100 }, 			
			{ label: '转正日期', name: 'confirmdate', index: 'confirmDate', width: 80 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
			{ label: '员工姓名', name: 'name', index: 'Name', width: 100 }, 			
			{ label: '员工性别', name: 'gender', index: 'gender', width: 100 }, 			
			{ label: '员工生日', name: 'birthday', index: 'birthday', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'} }, 			
			{ label: '员工证件类型', name: 'idtype', index: 'IdType', width: 100 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/cardtype/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.cardtype.cardname;
						}
					}
				});
				return result;
			}}, 			
			{ label: '员工证件号码', name: 'idno', index: 'IDNo', width: 100 }, 			
			{ label: '合同起期', name: 'startdate', index: 'Startdate', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
			{ label: '合同止期', name: 'enddate', index: 'EndDate', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
			{ label: '入职日期', name: 'entrydate', index: 'EntryDate', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
			{ label: '校区', name: 'schoolno', index: 'schoolNo', width: 50 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/school/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.school.schoolname;
						}
					}
				});
				return result;
			}}, 			
			{ label: '部门', name: 'deptno', index: 'deptNo', width: 50 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/department/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.department.name;
						}
					}
				});
				return result;
			}}, 			
			{ label: '职务', name: 'job', index: 'job', width: 80 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/jobcode/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.jobcode.dutyname;
						}
					}
				});
				return result;
			}}, 			
			{ label: '职级', name: 'jobgrade', index: 'jobGrade', width: 80 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/jobgradecode/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.jobgradecode.jobgradename;
						}
					}
				});
				return result;
			}}, 			
			{ label: '工资基准', name: 'salarygrade', index: 'salaryGrade', width: 80 }, 			
			{ label: '联系电话', name: 'phone', index: 'phone', width: 80 }, 			
			{ label: '微信', name: 'webchat', index: 'webchat', width: 80 }, 			
			{ label: '紧急联系人', name: 'contacter', index: 'contacter', width: 80 }, 			
			{ label: '紧急联系人电话', name: 'conphone', index: 'conphone', width: 80 }, 			
			{ label: '备用1', name: 'standbyflag1', index: 'StandByFlag1', width: 80 }, 			
			{ label: '备用2', name: 'standbyflag2', index: 'StandByFlag2', width: 80 }, 			
			{ label: '备用3', name: 'standbyflag3', index: 'StandByFlag3', width: 80 }		
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#giveperNojqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#giveperNojqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		guardian:{//监护人
			guardianNo:null,
			name:null
		},
		showQueryGivePerDiv:true,
		showList: true,
		title: null,
		activityinfo: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.activityinfo = {
					deptnoName:null,
    				activitiorName:null,
			    	confirmer:null,
	    			confirmerName:null
			};
		},
		update: function (event) {
			var activityno = getSelectedRow();
			if(activityno == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
           
            vm.getInfo(activityno);
		},
		saveOrUpdate: function (event) {
			var url = vm.activityinfo.activityno == null ? "generator/activityinfo/save" : "generator/activityinfo/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.activityinfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var activitynos = getSelectedRows();
			if(activitynos == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/activityinfo/delete",
                    contentType: "application/json",
				    data: JSON.stringify(activitynos),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(activityno){
			$.get(baseURL + "generator/activityinfo/info/"+activityno, function(r){
                vm.activityinfo = r.activityinfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
		queryPersion:function(){
			layer.open({
				type: 1,
				skin: 'layui-layer-molv',
				title: "查询员工",
				area: ['1000px', '650px'],
				shadeClose: false,
				content: jQuery("#queryGivePerDiv"),
				btn: ['完成','取消'],
				btn1: function (index) {
					
					var grid = $("#giveperNojqGrid");
				    var rowKey = grid.getGridParam("selrow");//取选中行的ID
				    var name = grid.jqGrid("getCell",rowKey,"name");//取选中行的name
				    var deptno = grid.jqGrid("getCell",rowKey,"deptno");//取选中行的name
				    
				    if(!rowKey){
				    	alert("请选择一条记录");
				    	return ;
				    }else{
				    	vm.activityinfo.activitior = rowKey;
				    	vm.activityinfo.activitiorName = name;
				    	
				    	
				    	
				    	$.ajax({
							type: "POST",
						    url: baseURL + "generator/department/infoDepartmentByEmployee/"+rowKey,
			                contentType: "application/json",
						    async : false,
						    success: function(r){
						    	if(r.code === 0){
						    		vm.activityinfo.deptno = r.department.departmentno;
						    		vm.activityinfo.deptnoName = r.department.name;
								}
							}
						});
				    	
				    	
				    	layer.close(index);
				    }
	            }
			});
		},
		queryPersion2:function(){
			layer.open({
				type: 1,
				skin: 'layui-layer-molv',
				title: "查询员工",
				area: ['1000px', '650px'],
				shadeClose: false,
				content: jQuery("#queryGivePerDiv"),
				btn: ['完成','取消'],
				btn1: function (index) {
					
					var grid = $("#giveperNojqGrid");
				    var rowKey = grid.getGridParam("selrow");//取选中行的ID
				    var name = grid.jqGrid("getCell",rowKey,"name");//取选中行的name
				    var deptno = grid.jqGrid("getCell",rowKey,"deptno");//取选中行的name
				    
				    if(!rowKey){
				    	alert("请选择一条记录");
				    	return ;
				    }else{
				    	vm.activityinfo.confirmer = rowKey;
				    	vm.activityinfo.confirmerName = name;
				    	layer.close(index);
				    }
	            }
			});
		},
		queryguardian:function(){
			vm.showQueryGivePerDiv = true;
			var page = $("#giveperNojqGrid").jqGrid('getGridParam','page');
			$("#giveperNojqGrid").jqGrid('setGridParam',{ 
				postData:vm.guardian,
                page:page
            }).trigger("reloadGrid");
		}
	}
});